home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / imap-3.0 / ANSI / c-client / os_aix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-06  |  17.3 KB  |  634 lines

  1. /*
  2.  * Program:    Operating-system dependent routines -- AIX version
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: MRC@CAC.Washington.EDU
  11.  *
  12.  * Date:    1 August 1988
  13.  * Last Edited:    6 July 1993
  14.  *
  15.  * Copyright 1993 by the University of Washington.
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notice appears in all copies and that both the
  20.  * above copyright notice and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made available
  24.  * "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  32.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35.  
  36. /* TCP input buffer */
  37.  
  38. #define BUFLEN 8192
  39.  
  40.  
  41. /* TCP I/O stream (must be before osdep.h is included) */
  42.  
  43. #define TCPSTREAM struct tcp_stream
  44. TCPSTREAM {
  45.   char *host;            /* host name */
  46.   char *localhost;        /* local host name */
  47.   int tcpsi;            /* input socket */
  48.   int tcpso;            /* output socket */
  49.   int ictr;            /* input counter */
  50.   char *iptr;            /* input pointer */
  51.   char ibuf[BUFLEN];        /* input buffer */
  52. };
  53.  
  54.  
  55. #include "mail.h"
  56. #include "osdep.h"
  57. #include <sys/time.h>
  58. #include <sys/socket.h>
  59. #include <netinet/in.h>
  60. #include <netdb.h>
  61. #include <ctype.h>
  62. #include <errno.h>
  63. extern int errno;        /* just in case */
  64. #include <pwd.h>
  65. #include <syslog.h>
  66. #include "misc.h"
  67. extern char *crypt();
  68.  
  69. extern long timezone;
  70. extern int daylight;
  71. extern char *tzname[2];
  72.  
  73. extern int sys_nerr;
  74. extern char *sys_errlist[];
  75.  
  76. /* Write current time in RFC 822 format
  77.  * Accepts: destination string
  78.  */
  79.  
  80. char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  81.  
  82. void rfc822_date (char *date)
  83. {
  84.   int zone,dstflag;
  85.   struct tm *t;
  86.   struct timeval tv;
  87.   struct timezone tz;
  88.   gettimeofday (&tv,&tz);    /* get time and timezone poop */
  89.   t = localtime (&tv.tv_sec);    /* convert to individual items */
  90.   tzset ();            /* get timezone from TZ environment stuff */
  91.   dstflag = daylight ? t->tm_isdst : 0;
  92.   zone = (dstflag * 60) - timezone/60;
  93.                 /* and output it */
  94.   sprintf (date,"%s, %d %s %d %02d:%02d:%02d %+02d%02d (%s)",
  95.        days[t->tm_wday],t->tm_mday,months[t->tm_mon],t->tm_year+1900,
  96.        t->tm_hour,t->tm_min,t->tm_sec,zone/60,abs (zone) % 60,
  97.        tzname[dstflag]);
  98. }
  99.  
  100. /* Get a block of free storage
  101.  * Accepts: size of desired block
  102.  * Returns: free storage block
  103.  */
  104.  
  105. void *fs_get (size_t size)
  106. {
  107.   void *block = malloc (size);
  108.   if (!block) fatal ("Out of free storage");
  109.   return (block);
  110. }
  111.  
  112.  
  113. /* Resize a block of free storage
  114.  * Accepts: ** pointer to current block
  115.  *        new size
  116.  */
  117.  
  118. void fs_resize (void **block,size_t size)
  119. {
  120.   if (!(*block = realloc (*block,size))) fatal ("Can't resize free storage");
  121. }
  122.  
  123.  
  124. /* Return a block of free storage
  125.  * Accepts: ** pointer to free storage block
  126.  */
  127.  
  128. void fs_give (void **block)
  129. {
  130.   free (*block);
  131.   *block = NIL;
  132. }
  133.  
  134.  
  135. /* Report a fatal error
  136.  * Accepts: string to output
  137.  */
  138.  
  139. void fatal (char *string)
  140. {
  141.   mm_fatal (string);        /* pass up the string */
  142.   syslog (LOG_ALERT,"IMAP C-Client crash: %s",string);
  143.   abort ();            /* die horribly */
  144. }
  145.  
  146. /* Copy string with CRLF newlines
  147.  * Accepts: destination string
  148.  *        pointer to size of destination string
  149.  *        source string
  150.  *        length of source string
  151.  */
  152.  
  153. char *strcrlfcpy (char **dst,unsigned long *dstl,char *src,unsigned long srcl)
  154. {
  155.   long i,j;
  156.   char *d = src;
  157.                 /* count number of LF's in source string(s) */
  158.   for (i = srcl,j = 0; j < srcl; j++) if (*d++ == '\012') i++;
  159.   if (i > *dstl) {        /* resize if not enough space */
  160.     fs_give ((void **) dst);    /* fs_resize does an unnecessary copy */
  161.     *dst = (char *) fs_get ((*dstl = i) + 1);
  162.   }
  163.   d = *dst;            /* destination string */
  164.                 /* copy strings, inserting CR's before LF's */
  165.   while (srcl--) switch (*src) {
  166.   case '\015':            /* unlikely carriage return */
  167.     *d++ = *src++;        /* copy it and any succeeding linefeed */
  168.     if (srcl && *src == '\012') {
  169.       *d++ = *src++;
  170.       srcl--;
  171.     }
  172.     break;
  173.   case '\012':            /* line feed? */
  174.     *d++ ='\015';        /* yes, prepend a CR, drop into default case */
  175.   default:            /* ordinary chararacter */
  176.     *d++ = *src++;        /* just copy character */
  177.     break;
  178.   }
  179.   *d = '\0';            /* tie off destination */
  180.   return *dst;            /* return destination */
  181. }
  182.  
  183.  
  184. /* Length of string after strcrlfcpy applied
  185.  * Accepts: source string
  186.  *        length of source string
  187.  */
  188.  
  189. unsigned long strcrlflen (STRING *s)
  190. {
  191.   unsigned long pos = GETPOS (s);
  192.   unsigned long i = SIZE (s);
  193.   unsigned long j = i;
  194.   while (j--) switch (SNX (s)) {/* search for newlines */
  195.   case '\015':            /* unlikely carriage return */
  196.     if (j && (CHR (s) == '\012')) {
  197.       SNX (s);            /* eat the line feed */
  198.       j--;
  199.     }
  200.     break;
  201.   case '\012':            /* line feed? */
  202.     i++;
  203.   default:            /* ordinary chararacter */
  204.     break;
  205.   }
  206.   SETPOS (s,pos);        /* restore old position */
  207.   return i;
  208. }
  209.  
  210. /* Server log in
  211.  * Accepts: user name string
  212.  *        password string
  213.  *        optional place to return home directory
  214.  * Returns: T if password validated, NIL otherwise
  215.  */
  216.  
  217. long server_login (char *user,char *pass,char **home,int argc,char *argv[])
  218. {
  219.   struct passwd *pw = getpwnam (lcase (user));
  220.                 /* no entry for this user or root */
  221.   if (!(pw && pw->pw_uid)) return NIL;
  222.                 /* validate password */
  223.   if (strcmp (pw->pw_passwd,(char *) crypt (pass,pw->pw_passwd))) return NIL;
  224.   setgid (pw->pw_gid);        /* all OK, login in as that user */
  225.   initgroups (user,pw->pw_gid);    /* initialize groups */
  226.   setuid (pw->pw_uid);
  227.                 /* note home directory */
  228.   if (home) *home = cpystr (pw->pw_dir);
  229.   return T;
  230. }
  231.  
  232. /* Return my user name
  233.  * Returns: my user name
  234.  */
  235.  
  236. char *uname = NIL;
  237.  
  238. char *myusername ()
  239. {
  240.   return uname ? uname : (uname = cpystr (getpwuid (geteuid ())->pw_name));
  241. }
  242.  
  243.  
  244. /* Return my home directory name
  245.  * Returns: my home directory name
  246.  */
  247.  
  248. char *hdname = NIL;
  249.  
  250. char *myhomedir ()
  251. {
  252.   return hdname ? hdname : (hdname = cpystr (getpwuid (geteuid ())->pw_dir));
  253. }
  254.  
  255.  
  256. /* Build status lock file name
  257.  * Accepts: scratch buffer
  258.  *        file name
  259.  * Returns: name of file to lock
  260.  */
  261.  
  262. char *lockname (char *tmp,char *fname)
  263. {
  264.   int i;
  265.   sprintf (tmp,"/tmp/.%s",fname);
  266.   for (i = 6; i < strlen (tmp); ++i) if (tmp[i] == '/') tmp[i] = '\\';
  267.   return tmp;            /* note name for later */
  268. }
  269.   
  270. /* TCP/IP open
  271.  * Accepts: host name
  272.  *        contact port number
  273.  * Returns: TCP/IP stream if success else NIL
  274.  */
  275.  
  276. TCPSTREAM *tcp_open (char *host,int port)
  277. {
  278.   TCPSTREAM *stream = NIL;
  279.   int sock;
  280.   char *s;
  281.   struct sockaddr_in sin;
  282.   struct hostent *host_name;
  283.   char hostname[MAILTMPLEN];
  284.   char tmp[MAILTMPLEN];
  285.   /* The domain literal form is used (rather than simply the dotted decimal
  286.      as with other Unix programs) because it has to be a valid "host name"
  287.      in mailsystem terminology. */
  288.                 /* look like domain literal? */
  289.   if (host[0] == '[' && host[(strlen (host))-1] == ']') {
  290.     strcpy (hostname,host+1);    /* yes, copy number part */
  291.     hostname[(strlen (hostname))-1] = '\0';
  292.     if ((sin.sin_addr.s_addr = inet_addr (hostname)) != -1) {
  293.       sin.sin_family = AF_INET;    /* family is always Internet */
  294.       strcpy (hostname,host);    /* hostname is user's argument */
  295.     }
  296.     else {
  297.       sprintf (tmp,"Bad format domain-literal: %.80s",host);
  298.       mm_log (tmp,ERROR);
  299.       return NIL;
  300.     }
  301.   }
  302.  
  303.   else {            /* lookup host name, note that brain-dead Unix
  304.                    requires lowercase! */
  305.     strcpy (hostname,host);    /* in case host is in write-protected memory */
  306.     if ((host_name = gethostbyname (lcase (hostname)))) {
  307.                 /* copy address type */
  308.       sin.sin_family = host_name->h_addrtype;
  309.                 /* copy host name */
  310.       strcpy (hostname,host_name->h_name);
  311.                 /* copy host addresses */
  312.       memcpy (&sin.sin_addr,host_name->h_addr,host_name->h_length);
  313.     }
  314.     else {
  315.       switch (h_errno) {
  316.     case HOST_NOT_FOUND:    /* authoritative error */
  317.       s = "No such host as %.80s";
  318.       break;
  319.     case TRY_AGAIN:        /* non-authoritative error */
  320.       s = "Transient error for host %.80s, try again";
  321.       break;
  322.     case NO_RECOVERY:    /* non-recoverable errors */
  323.       s = "Non-recoverable error looking up host %.80s";
  324.       break;
  325.     case NO_DATA:        /* no data record of requested type */
  326.       s = "No IP address known for host %.80s";
  327.       break;
  328.     default:
  329.       s = "Unknown error for host %.80s";
  330.       break;
  331.       }
  332.       sprintf (tmp,s,host);
  333.       mm_log (tmp,ERROR);
  334.       return NIL;
  335.     }
  336.   }
  337.  
  338.                 /* copy port number in network format */
  339.   if (!(sin.sin_port = htons (port))) fatal ("Bad port argument to tcp_open");
  340.                 /* get a TCP stream */
  341.   if ((sock = socket (sin.sin_family,SOCK_STREAM,0)) < 0) {
  342.     sprintf (tmp,"Unable to create TCP socket: %s",strerror (errno));
  343.     mm_log (tmp,ERROR);
  344.     return NIL;
  345.   }
  346.                 /* open connection */
  347.   if (connect (sock,(struct sockaddr *)&sin,sizeof (sin)) < 0) {
  348.     sprintf (tmp,"Can't connect to %.80s,%d: %s",hostname,port,
  349.          strerror (errno));
  350.     mm_log (tmp,ERROR);
  351.     return NIL;
  352.   }
  353.                 /* create TCP/IP stream */
  354.   stream = (TCPSTREAM *) fs_get (sizeof (TCPSTREAM));
  355.                 /* copy official host name */
  356.   stream->host = cpystr (hostname);
  357.                 /* get local name */
  358.   gethostname (tmp,MAILTMPLEN-1);
  359.   stream->localhost = cpystr ((host_name = gethostbyname (tmp)) ?
  360.                   host_name->h_name : tmp);
  361.                 /* init sockets */
  362.   stream->tcpsi = stream->tcpso = sock;
  363.   stream->ictr = 0;        /* init input counter */
  364.   return stream;        /* return success */
  365. }
  366.   
  367. /* TCP/IP authenticated open
  368.  * Accepts: host name
  369.  *        service name
  370.  * Returns: TCP/IP stream if success else NIL
  371.  */
  372.  
  373. TCPSTREAM *tcp_aopen (char *host,char *service)
  374. {
  375.   TCPSTREAM *stream = NIL;
  376.   struct hostent *host_name;
  377.   char hostname[MAILTMPLEN];
  378.   int i;
  379.   int pipei[2],pipeo[2];
  380.   /* The domain literal form is used (rather than simply the dotted decimal
  381.      as with other Unix programs) because it has to be a valid "host name"
  382.      in mailsystem terminology. */
  383.                 /* look like domain literal? */
  384.   if (host[0] == '[' && host[i = (strlen (host))-1] == ']') {
  385.     strcpy (hostname,host+1);    /* yes, copy without brackets */
  386.     hostname[i-1] = '\0';
  387.   }
  388.                 /* note that Unix requires lowercase! */
  389.   else if (host_name = gethostbyname (lcase (strcpy (hostname,host))))
  390.     strcpy (hostname,host_name->h_name);
  391.                 /* make command pipes */
  392.   if (pipe (pipei) < 0) return NIL;
  393.   if (pipe (pipeo) < 0) {
  394.     close (pipei[0]); close (pipei[1]);
  395.     return NIL;
  396.   }
  397.   if ((i = fork ()) < 0) {    /* make inferior process */
  398.     close (pipei[0]); close (pipei[1]);
  399.     close (pipeo[0]); close (pipeo[1]);
  400.     return NIL;
  401.   }
  402.   if (i) {            /* parent? */
  403.     close (pipei[1]);        /* close child's side of the pipes */
  404.     close (pipeo[0]);
  405.   }
  406.   else {            /* child */
  407.     dup2 (pipei[1],1);        /* parent's input is my output */
  408.     dup2 (pipei[1],2);        /* parent's input is my error output too */
  409.     close (pipei[0]); close (pipei[1]);
  410.     dup2 (pipeo[0],0);        /* parent's output is my input */
  411.     close (pipeo[0]); close (pipeo[1]);
  412.                 /* now run it */
  413.     execl ("/usr/ucb/rsh","rsh",hostname,"exec",service,0);
  414.     _exit (1);            /* spazzed */
  415.   }
  416.  
  417.                 /* create TCP/IP stream */
  418.   stream = (TCPSTREAM *) fs_get (sizeof (TCPSTREAM));
  419.                 /* copy official host name */
  420.   stream->host = cpystr (hostname);
  421.                 /* get local name */
  422.   gethostname (hostname,MAILTMPLEN-1);
  423.   stream->localhost = cpystr ((host_name = gethostbyname (hostname)) ?
  424.                   host_name->h_name : hostname);
  425.   stream->tcpsi = pipei[0];    /* init sockets */
  426.   stream->tcpso = pipeo[1];
  427.   stream->ictr = 0;        /* init input counter */
  428.   return stream;        /* return success */
  429. }
  430.  
  431. /* TCP/IP receive line
  432.  * Accepts: TCP/IP stream
  433.  * Returns: text line string or NIL if failure
  434.  */
  435.  
  436. char *tcp_getline (TCPSTREAM *stream)
  437. {
  438.   int n,m;
  439.   char *st,*ret,*stp;
  440.   char c = '\0';
  441.   char d;
  442.                 /* make sure have data */
  443.   if (!tcp_getdata (stream)) return NIL;
  444.   st = stream->iptr;        /* save start of string */
  445.   n = 0;            /* init string count */
  446.   while (stream->ictr--) {    /* look for end of line */
  447.     d = *stream->iptr++;    /* slurp another character */
  448.     if ((c == '\015') && (d == '\012')) {
  449.       ret = (char *) fs_get (n--);
  450.       memcpy (ret,st,n);    /* copy into a free storage string */
  451.       ret[n] = '\0';        /* tie off string with null */
  452.       return ret;
  453.     }
  454.     n++;            /* count another character searched */
  455.     c = d;            /* remember previous character */
  456.   }
  457.                 /* copy partial string from buffer */
  458.   memcpy ((ret = stp = (char *) fs_get (n)),st,n);
  459.                 /* get more data from the net */
  460.   if (!tcp_getdata (stream)) return NIL;
  461.                 /* special case of newline broken by buffer */
  462.   if ((c == '\015') && (*stream->iptr == '\012')) {
  463.     stream->iptr++;        /* eat the line feed */
  464.     stream->ictr--;
  465.     ret[n - 1] = '\0';        /* tie off string with null */
  466.   }
  467.                 /* else recurse to get remainder */
  468.   else if (st = tcp_getline (stream)) {
  469.     ret = (char *) fs_get (n + 1 + (m = strlen (st)));
  470.     memcpy (ret,stp,n);        /* copy first part */
  471.     memcpy (ret + n,st,m);    /* and second part */
  472.     fs_give ((void **) &stp);    /* flush first part */
  473.     fs_give ((void **) &st);    /* flush second part */
  474.     ret[n + m] = '\0';        /* tie off string with null */
  475.   }
  476.   return ret;
  477. }
  478.  
  479. /* TCP/IP receive buffer
  480.  * Accepts: TCP/IP stream
  481.  *        size in bytes
  482.  *        buffer to read into
  483.  * Returns: T if success, NIL otherwise
  484.  */
  485.  
  486. long tcp_getbuffer (TCPSTREAM *stream,unsigned long size,char *buffer)
  487. {
  488.   unsigned long n;
  489.   char *bufptr = buffer;
  490.   while (size > 0) {        /* until request satisfied */
  491.     if (!tcp_getdata (stream)) return NIL;
  492.     n = min (size,stream->ictr);/* number of bytes to transfer */
  493.                 /* do the copy */
  494.     memcpy (bufptr,stream->iptr,n);
  495.     bufptr += n;        /* update pointer */
  496.     stream->iptr +=n;
  497.     size -= n;            /* update # of bytes to do */
  498.     stream->ictr -=n;
  499.   }
  500.   bufptr[0] = '\0';        /* tie off string */
  501.   return T;
  502. }
  503.  
  504.  
  505. /* TCP/IP receive data
  506.  * Accepts: TCP/IP stream
  507.  * Returns: T if success, NIL otherwise
  508.  */
  509.  
  510. long tcp_getdata (TCPSTREAM *stream)
  511. {
  512.   fd_set fds;
  513.   FD_ZERO (&fds);        /* initialize selection vector */
  514.   if (stream->tcpsi < 0) return NIL;
  515.   while (stream->ictr < 1) {    /* if nothing in the buffer */
  516.     FD_SET (stream->tcpsi,&fds);/* set bit in selection vector */
  517.                 /* block and read */
  518.     if ((select (stream->tcpsi+1,&fds,0,0,0) < 0) ||
  519.     ((stream->ictr = read (stream->tcpsi,stream->ibuf,BUFLEN)) < 1)) {
  520.       close (stream->tcpsi);    /* nuke the socket */
  521.       if (stream->tcpsi != stream->tcpso) close (stream->tcpso);
  522.       stream->tcpsi = stream->tcpso = -1;
  523.       return NIL;
  524.     }
  525.     stream->iptr = stream->ibuf;/* point at TCP buffer */
  526.   }
  527.   return T;
  528. }
  529.  
  530. /* TCP/IP send string as record
  531.  * Accepts: TCP/IP stream
  532.  *        string pointer
  533.  * Returns: T if success else NIL
  534.  */
  535.  
  536. long tcp_soutr (TCPSTREAM *stream,char *string)
  537. {
  538.   return tcp_sout (stream,string,(unsigned long) strlen (string));
  539. }
  540.  
  541.  
  542. /* TCP/IP send string
  543.  * Accepts: TCP/IP stream
  544.  *        string pointer
  545.  *        byte count
  546.  * Returns: T if success else NIL
  547.  */
  548.  
  549. long tcp_sout (TCPSTREAM *stream,char *string,unsigned long size)
  550. {
  551.   int i;
  552.   fd_set fds;
  553.   FD_ZERO (&fds);        /* initialize selection vector */
  554.   if (stream->tcpso < 0) return NIL;
  555.   while (size > 0) {        /* until request satisfied */
  556.     FD_SET (stream->tcpso,&fds);/* set bit in selection vector */
  557.     if ((select (stream->tcpso+1,0,&fds,0,0) < 0) ||
  558.     ((i = write (stream->tcpso,string,size)) < 0)) {
  559.       puts (strerror (errno));
  560.       close (stream->tcpsi);    /* nuke the socket */
  561.       if (stream->tcpsi != stream->tcpso) close (stream->tcpso);
  562.       stream->tcpsi = stream->tcpso = -1;
  563.       return NIL;
  564.     }
  565.     size -= i;            /* count this size */
  566.     string += i;
  567.   }
  568.   return T;            /* all done */
  569. }
  570.  
  571. /* TCP/IP close
  572.  * Accepts: TCP/IP stream
  573.  */
  574.  
  575. void tcp_close (TCPSTREAM *stream)
  576. {
  577.  
  578.   if (stream->tcpsi >= 0) {    /* no-op if no socket */
  579.     close (stream->tcpsi);    /* nuke the socket */
  580.     if (stream->tcpsi != stream->tcpso) close (stream->tcpso);
  581.     stream->tcpsi = stream->tcpso = -1;
  582.   }
  583.                 /* flush host names */
  584.   fs_give ((void **) &stream->host);
  585.   fs_give ((void **) &stream->localhost);
  586.   fs_give ((void **) &stream);    /* flush the stream */
  587. }
  588.  
  589.  
  590. /* TCP/IP get host name
  591.  * Accepts: TCP/IP stream
  592.  * Returns: host name for this stream
  593.  */
  594.  
  595. char *tcp_host (TCPSTREAM *stream)
  596. {
  597.   return stream->host;        /* return host name */
  598. }
  599.  
  600.  
  601. /* TCP/IP get local host name
  602.  * Accepts: TCP/IP stream
  603.  * Returns: local host name
  604.  */
  605.  
  606. char *tcp_localhost (TCPSTREAM *stream)
  607. {
  608.   return stream->localhost;    /* return local host name */
  609. }
  610.  
  611. /* Copy memory block
  612.  * Accepts: destination pointer
  613.  *        source pointer
  614.  *        length
  615.  * Returns: destination pointer
  616.  */
  617.  
  618. char *memmove (char *s,char *ct,int n)
  619. {
  620.   bcopy (ct,s,n);        /* they should have this one */
  621.   return ct;
  622. }
  623.  
  624.  
  625. /* Return implementation-defined string corresponding to error
  626.  * Accepts: error number
  627.  * Returns: string for that error
  628.  */
  629.  
  630. char *strerror (int n)
  631. {
  632.   return (n >= 0 && n < sys_nerr) ? sys_errlist[n] : NIL;
  633. }
  634.